//
//  ZYImageRightButton.swift
//  SwiftDemo1
//
//  Created by wangzhipan on 2025/6/3.
//

import Foundation
import UIKit

class ZYImageRightButton: UIButton {
    convenience init(_ title: String, target: AnyObject, action: Selector) {
        self.init()
        setTitle(title+" ", for: .normal)
        setTitleColor(.black, for: .normal)
        addTarget(target, action: action, for: .touchUpInside)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        if let titleLabel = self.titleLabel {
            let imageRect = imageView?.frame ?? CGRect.zero
            titleLabel.frame.origin.x = 0
        }
        if let imageView = self.imageView {
            imageView.frame.origin.x = (titleLabel?.frame.origin.x ?? 0) + (titleLabel?.frame.size.width ?? 0)
        }
    }
}
